package org.edgegallery.mecm.apm.utils;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

/**
 * @program: mecm-apm
 * @description: 分页信息类
 * @author:
 * @create: 2022-10-12 14:32
 **/

@Setter
@Getter
public class PageResult<T> {
    @ApiModelProperty(value = "当前页面序号", example = "1")
    private Integer currentPage;

    @ApiModelProperty(value = "总记录数", example = "100")
    private Integer totalCount;

    @ApiModelProperty(value = "当前页面大小", example = "20")
    private Integer pageSize;

    @ApiModelProperty(value = "总页面数", example = "5")
    private Integer totalPage;

    private List<T> content;

    public PageResult(int currentPage, int pageSize, int totalCount, List<T> content){
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        if(content != null){
            this.content = content;
            this.totalPage = (int)Math.ceil((double)totalCount / (double)pageSize);
        }
    }
}
